package com.lemon.smartsafety.rayeye;

import com.flyco.tablayout.SegmentTabLayout;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.AppManager;
import com.lemon.smartsafety.entity.safe.company.CompanyInfo;
import com.lemon.smartsafety.rayeye.entity.Building;
import com.lemon.smartsafety.rayeye.entity.BundleKey;
import com.lemon.smartsafetynew.ui.activity.base.SwipeBackActivity;
import com.lemon.smartsafety.utils.app.HUDUtil;

import butterknife.Bind;

/**
 * Created by Cooliean on 16/4/15.
 */
public class FireAllListActivity extends SwipeBackActivity {

    private static String[] titles = {"故障", "火警"};
    @Bind(R.id.st_type)
    SegmentTabLayout segmentTabLayout;


    FaultFragment mFaultFragment;
    FireFragment  mFireFragment;

    private Building    mBuilding;
    private CompanyInfo mCompanyInfo;

    private int mBuildingId;


    @Override
    protected void getBundleArgs() {
        super.getBundleArgs();
        if (getIntent().getExtras() != null) {
            mBuilding = (Building) getIntent().getSerializableExtra(BundleKey.BUILDING);
            mCompanyInfo = (CompanyInfo) getIntent().getSerializableExtra(BundleKey.COMPANY_INFO);
        }
    }


    @Override
    protected void initTitle() {
        mToolBar.setTitle("");

    }

    @Override
    protected void callFinish() {
        AppManager.getAppManager().finishActivity(FireAllListActivity.class);
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_fire_all_list;
    }

    @Override
    protected void initViews() {
        super.initViews();
        if (mBuilding == null) {
            mHUDUtil.showErrorTip(getString(R.string.params_error), new HUDUtil.CallBack() {
                @Override
                public void onCall() {
                    callFinish();
                }
            });
            return;
        }


        mBuildingId = mBuilding.getBid();
        segmentTabLayout.setTabData(titles);
        segmentTabLayout.setOnTabSelectListener(segmentTagListener);
        replaceFragment(R.id.main_content, mFaultFragment = FaultFragment.newInstance(mCompanyInfo.getCompany_code(), mBuildingId));
    }

    private OnTabSelectListener segmentTagListener = new OnTabSelectListener() {
        @Override
        public void onTabSelect(int position) {
            if (position == 0) {
                replaceFragment(R.id.main_content, mFaultFragment = FaultFragment.newInstance(mCompanyInfo.getCompany_code(),mBuildingId));
            } else if (position == 1) {
                replaceFragment(R.id.main_content, mFireFragment = FireFragment.newInstance(mCompanyInfo.getCompany_code(),mBuildingId));
            }
        }

        @Override
        public void onTabReselect(int position) {

        }
    };


    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

}
